package lumis.content.control.contentpicker;

import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.portal.manager.ManagerFactory;
import lumis.portal.serviceinstance.ServiceInstanceConfig;
import lumis.service.categorization.CategorizationServiceInstanceProvider;

/**
 * Control that selects a term from the associated categorization service.
 *
 * @version $Revision: 9601 $ $Date: 2008-07-18 15:38:17 -0300 (Fri, 18 Jul 2008) $
 * @since 4.2.0
 */
public class TermPickerControl extends ContentPickerControl
{
	protected String getPopupRunTimeInterfaceDefinition() throws PortalException
	{
		ServiceInstanceConfig serviceInstanceConfig = ManagerFactory.getServiceInstanceManager().getServiceInstanceByDependency(SessionConfig.getCurrentSessionConfig(), this.douiContext.getRequest().getServiceInstanceConfig().getId(), CategorizationServiceInstanceProvider.REPOSITORY_ID, this.douiContext.getTransaction());
		if(serviceInstanceConfig == null)
			throw new PortalException("No categorization service associated to current service instance: "+this.douiContext.getRequest().getServiceInstanceConfig().getId());
		
		StringBuilder returnValue = new StringBuilder();
		returnValue.append("<interfaceId>" + getInterfaceId() + "</interfaceId>");
		returnValue.append("<addParameters>");
		returnValue.append("<parameter name=\"callbackFunction\">");
		returnValue.append("<value>" + getScriptCallBackFunctionName() + "</value>");
		returnValue.append("</parameter>");
		returnValue.append("</addParameters>");
		returnValue.append("<serviceInstanceId>"+serviceInstanceConfig.getId()+"</serviceInstanceId>");
		
		return returnValue.toString();
	}
}
